// pages/user/location/location.js

const app = getApp();

let City = require('../../../public/json/city.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    province: [], // 省份
    city:[], // 城市
    showProvinceId:String
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight - app.globalData.navHeight
        });
      }
    });
    this.setData({
      showProvinceId: 2,
      showCityId: 500,
      province: City,
      city: City[0]['child']
    })
    setTimeout(function () {
      that.setData({
        userLocationCity: app.globalData.userLocationCity
      })
      wx.hideLoading()
    }, 1000)
  },
  // 选择省
  changeProvince: function (e){
    var that = this;
    var id = (e.currentTarget.dataset.provinceid)-2;
    that.setData({
      showProvinceId: e.currentTarget.dataset.provinceid,
      userLocationCity: City[id]['child'][0]['name'],
      showCityId: City[id]['child'][0].id,
      city:City[id]['child']
    })
    app.globalData.userLocationProvince = City[id]['name'];

    app.globalData.userLocationCity = City[id]['child'][0]['name'];
  },
  // 选择城市
  changeCity:function(e){
    var that=this;
    var id = (e.currentTarget.dataset.cityid) - 2;
    console.log(e.currentTarget.dataset.cityname);
    that.setData({
      userLocationCity: e.currentTarget.dataset.cityname,
      showCityId: e.currentTarget.dataset.cityid,
    })
    app.globalData.userLocationCity = e.currentTarget.dataset.cityname;
  }
})